package com.jxx.controller;

import com.jxx.pojo.*;
import com.jxx.service.OrderService;
import com.jxx.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/order/")
public class OrderController {
    @Autowired
    private OrderService orderService;
    /**
    * @Description: 通过用户ID和订单状态查询订单
    * @Param: [orderStatus]
    * @return: com.jxx.vo.SysResult
    * @Author: laixinghua
    * @Date: 2020/11/28 0028 下午 3:22
    */
    @RequestMapping("findaddressByUserId/{orderStatus}/{rows}/{page}")
    public SysResult findAllOrderByUserId(@PathVariable Integer orderStatus,@PathVariable Integer page,@PathVariable Integer rows){
        Integer userId=1; //假数据
        //todo从服务器内拿userId
//        System.out.println(orderStatus);
       PageObject<Order> items=orderService.findAllOrderByUserIdAndOrderStatus(userId,orderStatus,page,rows);
        return SysResult.success(items);
    }
    /**
    * @Description: 删除订单
    * @Param: [orderId]
    * @return: com.jxx.vo.SysResult
    * @Author: laixinghua
    * @Date: 2020/12/8 0008 下午 2:36
    */
    @RequestMapping("deleteOrderByOrderId/{orderId}")
   public SysResult deleteOrderByOrderId(@PathVariable Integer orderId){
        int i = orderService.deleteOrderByOrderId(orderId);
        return SysResult.success();
    }
    /**
    * @Description: 更改订单状态
    * @Param: [orderStatus, orderId]
    * @return: com.jxx.vo.SysResult
    * @Author: laixinghua
    * @Date: 2020/12/8 0008 下午 2:44
    */
    @RequestMapping("updateOrderStatus/{orderStatus}/{orderId}")
    public SysResult updateOrderStatus(@PathVariable Integer orderStatus,@PathVariable Integer orderId) {
        Order order=new Order();
        order.setOrderId(orderId);
        order.setOrderStatus(orderStatus);
        orderService.updateOrderStatus(order);
        return SysResult.success();
    }
    @RequestMapping("findorderDetailByorderId/{orderId}")
    public SysResult findorderDetailByorderId(@PathVariable Integer orderId) {
        Order order = orderService.findorderDetailByorderId(orderId);
        return SysResult.success(order);
    }
}
